package lainey.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import lainey.ui.R;

public class TextHintDialog extends Dialog {

    private TextView mTvTitle;
    private TextView mTvMessage;
    private TextView mTvOK;

    public TextHintDialog(@NonNull Context context) {
        super(context, R.style.UI_DefaultDialogStyle);
        initDialog(context);
    }

    private void initDialog(Context context) {
        setContentView(R.layout.ui_dialog_text_hint);
        Window window = getWindow();
        if (window != null) {
            // 居中
            window.getAttributes().gravity = Gravity.CENTER;
        }
        // 点击返回按钮不取消
        setCancelable(true);
        // 点击空白不取消
        setCanceledOnTouchOutside(true);
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            setOwnerActivity(activity);
        }
        mTvTitle = findViewById(R.id.tv_title);
        mTvMessage = findViewById(R.id.tv_message);
        mTvOK = findViewById(R.id.tv_ok);
    }

    public void setOnClickListener(View.OnClickListener listener) {
        mTvOK.setOnClickListener(listener);
    }

    public void setMessage(String text) {
        mTvMessage.setText(text);
    }

    public void setMessage(int resId) {
        mTvMessage.setText(resId);
    }

    public void setTitle(String text) {
        mTvTitle.setText(text);
    }

    public void setTitle(int resId) {
        mTvTitle.setText(resId);
    }

    public void setOKText(String text) {
        mTvOK.setText(text);
    }

    public void setOKText(int resId) {
        mTvOK.setText(resId);
    }


}
